<?php
class LoginController extends CController {
	public function actionIndex() {
		$smarty = Yii::app ()->smarty;
		if (isset ( $_POST ) && ! empty ( $_POST )) {
			$passport = addslashes ( $_POST ['passport'] );
			$password = addslashes ( $_POST ['password'] );
			$_identity = new UserIdentity ( $passport, $password );
			$_identity->authenticate ();
			if ($_identity->errorCode === UserIdentity::ERROR_NONE) {
				Yii::app ()->user->login ( $_identity, 0 );
				$this->redirect(array("/main"));
			} else {
				if ($_identity->errorCode == 1) {
					$error = "账号不存在";
				} elseif ($_identity->errorCode) {
					$error = "密码不正确";
				}
				$smarty->assign ( "error", $error );
			}
		}
		$smarty->display ( 'login.html' );
	}
}
?>